import request from "../utils/request";
export const getGoodsList = (query, pagenum, pagesize) => {
  return request({
    url: "/goods",
    method: "get",
    params: { query, pagenum, pagesize },
  });
};

export const getGoodsCategories = (categories, pagenum, pagesize) => {
  return request({
    url: "/categories",
    method: "get",
    params: { type: categories, pagenum, pagesize },
  });
};
export const getCategories = (id, sel) => {
  return request({
    url: `/categories/${id}/attributes`,
    method: "get",
    params: { sel },
  });
};
export const EditAxisCategories = (attrId, catId, attrSel) => {
  return request({
    url: `/categories/${catId}/attributes/${attrId}`,
    method: "get",
    params: { attr_sel: attrSel },
  });
};

export const EditCategoriesName = (
  attrId,
  catId,
  attrSel,
  attrName,
  attrVals
) => {
  return request({
    url: `/categories/${catId}/attributes/${attrId}`,
    method: "put",
    data: {
      attr_sel: attrSel,
      attr_name: attrName,
      attr_vals: attrVals.join(","),
    },
  });
};

export const addCategoriesName = (cat_id, attr_name, attr_sel) => {
  return request({
    url: `/categories/${cat_id}/attributes`,
    method: "post",
    data: { attr_sel, attr_name },
  });
};
export const delCategoriesName = (cat_id, attr_id) => {
  return request({
    url: `categories/${cat_id}/attributes/${attr_id}`,
    method: "delete",
  });
};
export const addCategories = (name, id, level) => {
  return request({
    url: "/categories",
    method: "post",
    data: { cat_pid: id, cat_name: name, cat_level: level },
  });
};

export const delCategories = (id) => {
  return request({
    url: "/categories/" + id,
    method: "delete",
  });
};
export const EditCategories = (id, cat_name) => {
  return request({
    url: "/categories/" + id,
    method: "put",
    data: { cat_name },
  });
};
export const delGoods = (id) => {
  return request({
    url: `/goods/${id}`,
    method: "delete",
  });
};
